<!--
 * @name score
 * @description 组件描述
 * @author idouya
 * @email elegentfrog@163.com
 * @date 2025-07-03
 -->

<template>
  <div class="p-score common-bg common-layout">
    <page-title
      :discipline="gameInfo.discipline"
      :event="gameInfo.event"
      :match="gameInfo.match"
      :type="gameInfo.type"
      :eventName="gameInfo.eventName"
      :showTime="true"
    ></page-title>
    <div class="content">
      <div class="content-top">
        <div class="line1">
          <div class="order">{{ scoreData.Order }}</div>
          <div class="name">{{ scoreData.AthleteName }}</div>
          <div class="club">{{ scoreData.CountryName }}</div>
        </div>
        <div class="line1">
          <div class="order horseOrder">{{ scoreData.HorseOrder }}</div>
          <div class="name horseName">{{ scoreData.HorseName }}</div>
          <div class="line1-time">
            <div class="time">
              {{ scoreData.time }}
            </div>
          </div>
        </div>
      </div>
      <div class="content-bottom">
        <div class="header">
          <template v-for="(item, index) in scoreList" :key="index">
            <div class="header-item" style="width: 33.33%" v-if="item?.value">
              <div class="header-item-title">{{ item?.label }}</div>
              <div :class="['header-item-score', item?.value ? '' : 'hide']">
                {{ item?.value || '0' }}
              </div>
            </div>
          </template>
          <!-- <div class="header-item" v-if="scoreData?.M">
            <div class="header-item-title">M</div>
            <div :class="['header-item-score', scoreData?.M ? '' : 'hide']">
              {{ scoreData?.M || '0' }}
            </div>
          </div>
          <div class="header-item" v-if="scoreData?.H">
            <div class="header-item-title">H</div>
            <div :class="['header-item-score', scoreData?.H ? '' : 'hide']">
              {{ scoreData?.H || '0' }}
            </div>
          </div>
          <div class="header-item" v-if="scoreData?.C">
            <div class="header-item-title">C</div>
            <div :class="['header-item-score', scoreData?.C ? '' : 'hide']">
              {{ scoreData?.C || '0' }}
            </div>
          </div>
          <div class="header-item" v-if="scoreData?.E">
            <div class="header-item-title">E</div>
            <div :class="['header-item-score', scoreData?.E ? '' : 'hide']">
              {{ scoreData?.E || '0' }}
            </div>
          </div>
          <div class="header-item" v-if="scoreData?.B">
            <div class="header-item-title">B</div>
            <div :class="['header-item-score', scoreData?.B ? '' : 'hide']">
              {{ scoreData?.B || '0' }}
            </div>
          </div> -->
        </div>
        <div class="footer">
          <div class="footer-item">得分</div>
          <div class="footer-item">{{ scoreData?.Score || '' }}</div>
          <div class="footer-item">罚分</div>
          <div class="footer-item">{{ scoreData?.CurResult || '' }}</div>
          <div class="footer-item">当前排名</div>
          <div class="footer-item rank">{{ scoreData?.Rank || '' }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import Config from '@/assets/js/config'
import { useMultiProcRequest } from '@/assets/js/useMultiProcRequest'

const { results, fetchForProcs } = useMultiProcRequest()

const gameInfo = ref({
  discipline: '马术',
  match: '',
  event: 'EVENTEAM',
  type: '个人成绩公告',
  eventName: '',
  matchType: '',
})

const atheleteInfo = ref({
  order: 1,
  name: '杨舒涵',
  delegation: '中国',
  horseOrder: 201,
  club: '好骑士嘉豪马术',
  horseName: 'Joanna',
  time: '00:00',
})

const scoreData = ref({})
const scoreList = ref([])

const { proxy } = getCurrentInstance()
const router = useRouter()
const route = useRoute()
const params = ref({})
const procName = ref([])

onBeforeMount(() => {})
onMounted(() => {
  params.value = route.query
  procName.value = Config.procNameList[route.name]
  getData()
})

const getData = async () => {
  if (procName.value.length > 0) {
    fetchForProcs(procName.value, {
      procName: procName.value[0],
      keyValues: params.value,
    })
  }
}

watchEffect(() => {
  if (results.value?.datasetList?.length) {
    gameInfo.value.event = results.value.datasetList[0][0]?.EventCode
    gameInfo.value.match = results.value.datasetList[0][0]?.MatchName
    scoreData.value = results.value.datasetList[0][0]
    gameInfo.value.eventName = results.value.datasetList[0][0]?.EventName
    gameInfo.value.matchType = results.value.datasetList[0][0]?.MatchType
    const judgeList = results.value.datasetList[2]
    const score = results.value.datasetList[0][0]
    if (judgeList) {
      scoreList.value = judgeList.map((item) => {
        return {
          label: item.col,
          value: score[item.col],
        }
      })
    }
  }
})

watch(
  () => route.query,
  (val) => {
    params.value = val
    getData()
  }
)
</script>

<style scoped lang="scss">
@import '@/assets/scss/dressage/score4';
</style>
